from django import forms
from django.contrib.auth.models import User

import ps3t.myps3t.models as db
from datetime import datetime

from django.forms import ModelForm

class RegistrationForm(forms.Form):

	username   = forms.CharField(label=u'Nome (PSN_ID)'  , max_length=30)
	first_name = forms.CharField(label=u'Primeiro Nome', max_length=50)
	last_name  = forms.CharField(label=u'Sobrenome'    , max_length=50)
	email      = forms.EmailField(label=u'E-mail')
	birth      = forms.DateField(widget=forms.DateInput(format = '%d/%m/%Y'), input_formats=('%d/%m/%Y',))

	password1 = forms.CharField(label=u'Password',
								widget=forms.PasswordInput(render_value=False))

	password2 = forms.CharField(label=u'Password (again)',
								widget=forms.PasswordInput(render_value=False))

	def clean_username(self):
		try:
			user = User.objects.get(username=self.cleaned_data["username"])
		except User.DoesNotExist:
			return self.cleaned_data["username"]
		else:
			raise forms.ValidationError(u'Usuario ja cadastrado, escolha outro')

	def clean_password2(self):
			if self.cleaned_data["password1"] == self.cleaned_data["password2"]:
				return self.cleaned_data["password2"]

			raise forms.ValidationError(u'As senhas devem ser iguais')

class BoostForm(ModelForm):
	class Meta:
		model = db.boost

class BoostUserForm(ModelForm):
	class Meta:
		model = db.boost_user

class BoostTrophyForm(forms.ModelForm):
    class Meta:
        model = db.boost_trophy
        exclude = ('pub_date', )

